//
//  JANewsNormalCell.m
//  网易新闻
//
//  Created by Arvin on 17/3/19.
//  Copyright © 2017年 Arvin. All rights reserved.
//

#import "JANewsNormalCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>



@implementation JANewsNormalCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    
    return self;
}

-(void)setupUI{
    
    //间距
   CGFloat intervalOne = 8;
    CGFloat intervalTwo = 10;

    
    //1.创建并添加子控件
    
    //图片
    _newsImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_newsImage];
    
    //标题
    _newsTitle = [[UILabel alloc]init];
    [self.contentView addSubview:_newsTitle];
    _newsTitle.font = [UIFont systemFontOfSize:18];
    _newsTitle.textColor = [UIColor blackColor];
    _newsTitle.numberOfLines = 0;
    
    //新闻来源
    _source = [[UILabel alloc]init];
    [self.contentView addSubview:_source];
    _source.font = [UIFont systemFontOfSize:15];
    _source.textColor = [UIColor lightGrayColor];
    
    
    //回复数
    _replyCount = [[UILabel alloc]init];
    [self.contentView addSubview:_replyCount];
    _replyCount.font = [UIFont systemFontOfSize:15];
    _replyCount.textColor = [UIColor lightGrayColor];
    
    
    //自动布局
    [_newsImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(intervalOne);
//        make.left.equalTo(self.contentView).offset(intervalTwo);
        make.bottom.equalTo(self.contentView).offset(-intervalOne);
        make.size.mas_equalTo(CGSizeMake(102, 76));

    }];
    
    [_newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_newsImage);
        make.left.equalTo(_newsImage.mas_right).offset(intervalTwo);
        make.right.equalTo(self.contentView.mas_right).offset(-intervalTwo);
        
    }];
    
    [_source mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_newsImage);
        make.left.equalTo(_newsImage.mas_right).offset(intervalTwo);
    }];
    
    [_replyCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_newsImage);
        make.right.equalTo(self.contentView).offset(-intervalTwo);
    }];
    
}

-(void)setModel:(JANewsModel *)model{
    _model = model;
    [_newsImage sd_setImageWithURL:[NSURL URLWithString:_model.imgsrc]];
    _newsTitle.text = model.title;
    _source.text = model.source;
    _replyCount.text = model.replyCount;
}

@end
